//
//  ViralInflectionViewCell.m
//  yilutongxing
//
//  Created by T&J on 2017/6/30.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "ViralInflectionViewCell.h"
#import "YZEUI_ToggleButton.h"
#import <Masonry.h>

@interface ViralInflectionViewCell ()
@property(nonatomic,strong) YZEUI_ToggleButton *pnbtn;//阴阳性按钮
@end

@implementation ViralInflectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.accessoryType = UITableViewCellAccessoryNone;
    //初始化UI控件
    YZEUI_ToggleButton *btn = [[YZEUI_ToggleButton alloc]initWithTitle:@"阴性" selectedtitle:@"阳性"];
    btn.tag = 1;
    self.pnbtn = btn;
    [self.contentView addSubview:btn];
    
    //默认是定性
    self.isP = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    return;
}

- (void)setIsP:(BOOL)isP{
    //debugLog(@"[VCELL]%@", self.accessibilityIdentifier);
    if (isP) {
        _typetitleLabel.text = @"定性";
        _pnbtn.hidden = NO;
        _amountTF.hidden = YES;
        _unitLabel.hidden = YES;
    }
    else {
        _typetitleLabel.text = @"定量";
        _pnbtn.hidden = YES;
        _amountTF.hidden = NO;
        _unitLabel.hidden = NO;
    }
    
    _isP = isP;
}

-(void)giveVal:(NSString *)val{
    if (_isP) {
        if ([val isEqualToString:@"阴性"]) {
            _pnbtn.selected = NO;
        }
        else if ([val isEqualToString:@"阳性"]){
            _pnbtn.selected = YES;
        }
    }
    else{
        _amountTF.text = val;
    }
}

-(NSString*)getVal{
    NSString *val;
    if (_isP) {
        if (_pnbtn.selected) {
            val = @"阳性";
        }
        else {
            val = @"阴性";
        }
    }
    else {
        val = _amountTF.text;
    }
    return val;
}

- (void)updateConstraints{
    [self.pnbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.contentView.mas_right).offset(-15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    [super updateConstraints];
}

@end
